package com.qf.java2201.web;

import com.alibaba.fastjson.JSON;
import com.qf.java2201.common.R;
import com.qf.java2201.service.OrderService;
import com.qf.java2201.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

//检查某日期 某时间段 某医生 预约人数是否已满
@WebServlet("/checkDate")
public class CheckDateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String odate = req.getParameter("odate");
        String sjdid = req.getParameter("sjdid");
        String edid = req.getParameter("edid");

        OrderService orderService = new OrderServiceImpl();
        System.out.println(odate);
        System.out.println(sjdid);
        System.out.println(edid);

       boolean b = orderService.checkDate(odate, sjdid, edid);
        PrintWriter writer = resp.getWriter();
        if (b) {
            R ok = R.ok();
            String s = JSON.toJSONString(ok);
            writer.println(s);
        } else {
            R error = R.error();
            String s = JSON.toJSONString(error);
            writer.println(s);
        }

    }
}
